package edu.zju.gis.dbfg.common.model;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.geotools.geojson.geom.GeometryJSON;
import org.json.JSONObject;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.io.ParseException;
import org.locationtech.jts.io.WKTReader;


/**
 * @author Hu
 * @date 2019/9/28
 * LCRA 数据 model 类
 * LCRA 的 shape 为：MultiPolygon 或者 Polygon
 **/
@Getter
@Setter
@ToString
public class LCRA extends Feature {

  private String id;
  private Long objID;
  private String fidLca110;
  private Long fidLca1_1;
  private Long fidLcra_1;
  private String cc;
  private Long tag;
  private String featid;
  private String elemSTime;
  private String elemETime;
  private Long areaCode;
  private Long fidBoua11;
  private String name;
  private String pac;
  private Long fidLca1_2;
  private Long fidLcra_2;
  private String cc1;
  private Long tag1;
  private String featid1;
  private String elemSTime_;
  private String elemETime_;
  private Long areaCode1;
  private String feature;
  private Long changeType;
  private Long fidBoua1;
  private String name1;
  private String pac1;
  private Long fidLca1_3;
  private Long fidLca1_4;
  private Long fidLcra_3;
  private String cc12;
  private Long tag12;
  private String featid12;
  private String elemSTime1;
  private String elemETime1;
  private Long areaCode2;
  private String feature1;
  private String ccp;
  private Long changeType1;
  private Long changeType2;
  private Long fidBoua2;
  private String name12;
  private String pac12;
  private Long fidLca1_5;
  private Long fidLca;
  private String cc1213;
  private Long tag1213;
  private String featid12_;
  private String elemSTime_1;
  private String elemETime_1;
  private Long areaCode3;
  private Long changeType3;
  private String feature12;
  private String fImportti;
  private String fFrame;
  private String fGuid;
  private Long fYear;
  private Double fLength;
  private Double fArea;
  private Long partitionn;
  private String ccp1;
  private String fLabel;
  private Long changeType4;
  private Long fidBoua3;
  private String name1213;
  private String pac1213;
  //private String ff;
  private Double shapeLength;
  private Double shapeArea;
  private Double areaM2;
  private Geometry shape;

  public String toGeoJson() throws ParseException {
    JSONObject json = new JSONObject();
    json.put("id", this.id);
    json.put("objID", this.objID);//fid
    json.put("fidLca1_1", this.fidLca1_1);
    json.put("fidLca110", this.fidLca110);
    json.put("fidLcra_1", this.fidLcra_1);
    json.put("cc", this.cc);
    json.put("tag", this.tag);
    json.put("featid", this.featid);
    json.put("elemSTime", this.elemSTime);
    json.put("elemETime", this.elemETime);
    json.put("areaCode", this.areaCode);
    json.put("fidBoua11", this.fidBoua11);
    json.put("name", this.name);
    json.put("pac", this.pac);
    json.put("fidLca1_2", this.fidLca1_2);
    json.put("fidLcra_2", this.fidLcra_2);
    json.put("cc1", this.cc1);
    json.put("tag1", this.tag1);
    json.put("featid1", this.featid1);
    json.put("elemSTime_", this.elemSTime_);
    json.put("elemETime_", this.elemETime_);
    json.put("areaCode1", this.areaCode1);
    json.put("feature", this.feature);
    json.put("changeType", this.changeType);
    json.put("fidBoua1", this.fidBoua1);
    json.put("name1", this.name1);
    json.put("pac1", this.pac1);
    json.put("fidLca1_3", this.fidLca1_3);
    json.put("fidLca1_4", this.fidLca1_4);
    json.put("fidLcra_3", this.fidLcra_3);
    json.put("cc12", this.cc12);
    json.put("tag12", this.tag12);
    json.put("featid12", this.featid12);
    json.put("elemSTime1", this.elemSTime1);
    json.put("elemETime1", this.elemETime1);
    json.put("areaCode2", this.areaCode2);
    json.put("feature1", this.feature1);
    json.put("ccp", this.ccp);
    json.put("changeType1", this.changeType1);
    json.put("changeType2", this.changeType2);
    json.put("fidBoua2", this.fidBoua2);
    json.put("name12", this.name12);
    json.put("pac12", this.pac12);
    json.put("fidLca1_5", this.fidLca1_5);
    json.put("fidLca", this.fidLca);
    json.put("cc1213", this.cc1213);
    json.put("tag1213", this.tag1213);
    json.put("featid12_", this.featid12_);
    json.put("elemSTime_1", this.elemSTime_1);
    json.put("elemETime_1", this.elemETime_1);
    json.put("areaCode3", this.areaCode3);
    json.put("feature12", this.feature12);
    json.put("changeType3", this.changeType3);
    json.put("fImportti", this.fImportti);
    json.put("fFrame", this.fFrame);
    json.put("fGuid", this.fGuid);
    json.put("fYear", this.fYear);
    json.put("fLength", this.fLength);
    json.put("fArea", this.fArea);
    json.put("partitionn", this.partitionn);
    json.put("ccp1", this.ccp1);
    json.put("fLabel", this.fLabel);
    json.put("changeType4", this.changeType4);
    json.put("fidBoua3", this.fidBoua3);
    json.put("name1213", this.name1213);
    json.put("pac1213", this.pac1213);
    //json.put("ff", this.ff);
    json.put("shapeLength", this.shapeLength);
    json.put("shapeArea", this.shapeArea);
    json.put("areaM2", this.areaM2);

    WKTReader reader = new WKTReader();
    Geometry geometry = reader.read(this.shape.toText());
    GeometryJSON g = new GeometryJSON(9);
    String geojson = g.toString(geometry);
    JSONObject geo = new JSONObject(geojson);
    geo.put("orientation", "counterclockwise");
    json.put("shape", geo);
    return json.toString();
  }

}
